package dao.admin.impl;

import dao.BaseDao;
import dao.admin.ManagerListDao;
import entity.Books;
import entity.Manager;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * ManagerListDaoImpl
 *
 * @author ChenYanMei
 * @version 2023/9/4
 */
public class ManagerListDaoImpl extends BaseDao implements ManagerListDao {
    /**
     * 查询人员信息
     * @return
     */
    @Override
    public List<Manager> getList() {
        String sql = "select * from manager ";
        List<Manager> list = new ArrayList<>();
        Manager manager = null;
        Connection conn = getConnection();
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            while (rs.next()){
                manager = new Manager();
                manager.setId(rs.getInt("id"));
                manager.setAccount(rs.getString("account"));
                manager.setName(rs.getString("name"));
                manager.setEmail(rs.getString("email"));
                list.add(manager);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            closeAll(rs,pstmt,conn);
        }
        return list;
    }
}
